package com.senlingspace.web.controller.weixin.project;

import com.alibaba.fastjson2.JSON;
import com.senlingspace.common.core.controller.BaseController;
import com.senlingspace.common.core.domain.AjaxResult;
import com.senlingspace.common.enums.OrderSource;
import com.senlingspace.framework.security.context.SecurityUtilExt;
import com.senlingspace.system.domain.SlkjWechatSmall;
import com.senlingspace.system.service.IProjectService;
import com.senlingspace.system.service.ISlkjFareSchemeService;
import com.senlingspace.system.service.ISlkjWechatSmallService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;


@Slf4j
@Validated
@AllArgsConstructor
@RestController
@RequestMapping(path = "/wmp/project/v1")
public class MiniAppProjectController extends BaseController {

    private IProjectService projectService;
    private final ISlkjFareSchemeService iSlkjFareSchemeService;
    private ISlkjWechatSmallService wechatSmallService;


    @GetMapping("/smallImgUrl")
    public AjaxResult getWechatSmallImgUrl(@RequestParam(required = true) String modules,@RequestParam(required = true) String modulesType) {
        SlkjWechatSmall slkjWechatSmall = new SlkjWechatSmall();
        slkjWechatSmall.setModules(modules);
        slkjWechatSmall.setModulesType(modulesType);
        return AjaxResult.success(wechatSmallService.selectSlkjWechatSmallList(slkjWechatSmall));
    }

    /**
     * 微信小程序 项目详情
     * */
    @GetMapping("/details")
    public AjaxResult getShopAndProjectDetails(@RequestParam(required = false) Long shopId) {
        if (shopId == null) {
            return AjaxResult.success( projectService.getShopAndProjectDetails(SecurityUtilExt.getShopId()) );
        }
        return AjaxResult.success( projectService.getShopAndProjectDetails(shopId) );
    }

    /**
     * 微信小程序 票档选择
     *
     * @return {@link AjaxResult }
     */
    @GetMapping(path = "/projects")
    public AjaxResult projects() {

        log.info("获取门店 [{}] 当前正在上映的项目门店价格信息！", SecurityUtilExt.getShopId());

        if (Objects.isNull(SecurityUtilExt.getShopId())) {
            return error("参数不能为空！");
        }
        AjaxResult projects = iSlkjFareSchemeService.projects(SecurityUtilExt.getShopId(), OrderSource.MINI_PROGRAM.getCode());
        log.info("门店 [{}] 价格信息：{}", SecurityUtilExt.getShopId(), JSON.toJSONString(projects));
        return projects;
    }

}
